package com.rst.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rst.dao.ExamDAO;
import com.rst.dao.ExamGradingLevelDAO;
import com.rst.dao.ExamGroupsDAO;
import com.rst.dao.ExamScoresDAO;
import com.rst.model.Exam;
import com.rst.model.ExamGradingLevels;
import com.rst.model.ExamGroups;
import com.rst.model.ExamScore;

@Service
public class ExamService {

	@Autowired
	private ExamDAO examDAO;
	
	@Autowired
	private ExamGradingLevelDAO examGradingLevelsDAO;
	
	@Autowired
	private ExamGroupsDAO examGroupsDAO;
	
	@Autowired
	private ExamScoresDAO examScoresDAO;
	
	
	//private Logger logger = Logger.getLogger(ExamService.class);
	
	
	
	public void saveExamGradingLevels(ExamGradingLevels examGradingLevels) {
		examGradingLevelsDAO.saveExamGradingLevels(examGradingLevels);		
	}

	public ExamGradingLevels getExamGradingLevelsById(Long examGradingLevelsId) {
		return examGradingLevelsDAO.getExamGradingLevelsById(examGradingLevelsId);
	}

	public List<ExamGradingLevels> getExamGradingLevelsList() {
		return examGradingLevelsDAO.getExamGradingLevelsList();
	}

	public String deleteExamGradingLevels(Long examGradingLevelsId) {
		ExamGradingLevels examGradingLevels =  examGradingLevelsDAO.getExamGradingLevelsById(examGradingLevelsId);
		examGradingLevels.setStatus(ExamGradingLevels.INACTIVE);
		examGradingLevelsDAO.updateExamGradingLevels(examGradingLevels);		
		return "success";
	}
	public void updateExamGradingLevels(ExamGradingLevels examGradingLevels, Long examGradingLevelsId) {
		examGradingLevels.setId(examGradingLevelsId);
		examGradingLevelsDAO.updateExamGradingLevels(examGradingLevels);				
	}


	
	
	public void saveExamGroups(ExamGroups examGroups) {
		examGroupsDAO.saveExamGroups(examGroups);
		
	}

	public ExamGroups getExamGroupsById(Long examGroupsId) {
		return examGroupsDAO.getExamGroupsById(examGroupsId);
		
	}

	public List<ExamGroups> getExamGroupsList() {
		return examGroupsDAO.getExamGroupsList();
	}

	public String deleteExamGroups(Long examGroupsId) {
		ExamGroups examGroups =  examGroupsDAO.getExamGroupsById(examGroupsId);
		examGroups.setStatus(ExamGroups.INACTIVE);
		examGroupsDAO.saveExamGroups(examGroups);
		return "success";
	}
	public void updateExamGroups(ExamGroups examGroups, Long examGroupId) {
		examGroups.setId(examGroupId);
		examGroupsDAO.updateExamGroups(examGroups);		
	}

	
	
	
	
	public void saveExam(Exam exam) {
		examDAO.saveExam(exam);		
	}

	public Exam getExamById(Long examId) {
		return examDAO.getExamById(examId);
	}

	public List<Exam> getExamList() {
		return examDAO.getExamList();
	}

	public String deleteExam(Long examId) {
		Exam exam =  examDAO.getExamById(examId);
		exam.setStatus(Exam.INACTIVE);
		examDAO.saveExam(exam);	
		return "success";
	}

	public void updateExam(Exam exam, Long examId) {
		exam.setId(examId);
		examDAO.updateExam(exam);			
	}

	
	
	
	public void saveExamScore(ExamScore examScore) {
		examScoresDAO.saveExamScore(examScore);
		
	}

	public ExamScore getExamScoreById(Long examScoreId) {
		return examScoresDAO.getExamScoreById(examScoreId);
	}

	public List<ExamScore> getExamScoreList(Long examId) {
		return examScoresDAO.getExamScoreList(examId);
	}

	public String deleteExamScore(Long examScoreId) {
		ExamScore examScore =  examScoresDAO.getExamScoreById(examScoreId);
		examScore.setStatus(ExamScore.INACTIVE);
		examScoresDAO.saveExamScore(examScore);
		return "success";
	}
	
	public void updateExamScore(ExamScore examScore, Long examScoreId) {
		examScore.setId(examScoreId);
		examScoresDAO.updateExamScore(examScore);	
		
	}
	
	
	

} 

